package com.tich.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 后端统一返回结果
 * */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {

    private Integer code;
    private String msg;//异常信息
    private T data;

    public static <T> Result<T> success(){
        Result<T> result = new Result<T>();
        result.code = 200;
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<T>();
        result.code = 200;
        result.data = data;
        return result;
    }

    public static <T> Result<T> success(String msg){
        Result<T> result = new Result<T>();
        result.code = 200;
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> success(String msg, T data){
        Result<T> result = new Result<T>();
        result.code = 200;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <T> Result<T> error(Integer code, String msg){
        Result<T> result = new Result<T>();
        result.code = code;
        result.msg = msg;
        return result;
    }
}